package logic

import (
	"context"
	"doctor-medicine-system/model/mysql"

	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MediListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMediListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MediListLogic {
	return &MediListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MediListLogic) MediList(in *doctorrpc.MediListRequest) (*doctorrpc.MediListResponse, error) {
	// todo: add your logic here and delete this line

	var medis []mysql.Medi
	mysql.DB.Debug().Find(&medis)

	var MediList []*doctorrpc.MediList

	for _, medi := range medis {
		list := doctorrpc.MediList{
			Name:      medi.Name,
			MediImage: medi.MediImage,
			Price:     medi.Price,
			Start:     medi.Start,
			MediId:    int64(medi.ID),
		}
		MediList = append(MediList, &list)
	}

	return &doctorrpc.MediListResponse{
		List: MediList,
	}, nil
}
